<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt"  prefix="fmt"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>添加评论</title>
<link rel="stylesheet" href="${pageContext.request.contextPath }/static/css/bootstrap.css"/>
<link rel="stylesheet" href="${pageContext.request.contextPath }/static/css/2.css"/>
</head>
<body> 
<div class="page-header">
    <h1>添加评论</h1>
    <h1 id="addInfo" style="color: red"></h1>
</div>
<form action="" method="" id="form" >
    <table class="table table-hover">
        <input type="hidden" name="id" value="${entry.id}">
        <tr class="active">
            <td>
                <label for="uploader">图书名称:</label></td>
            <td>
                <input type="text" value="${entry.title}"  class="form-control" name="title" id="title" placeholder="请输入图书标题">
            </td>
        </tr>
        <tr class="warning">
            <input type="hidden" value="${id}" name="nid" id="nid">
            <td><label for="summary">图书摘要:</label></td>
            <td>
                <div class="form-group">
                    <textarea id="summary" value="" style="resize: none" name="summary" class="form-control" rows="3" placeholder="请输入摘要">${entry.summary}</textarea>
                </div>
            </td>
        </tr>
        <tr class="active">
            <td>
                <label for="uploader">上传人:</label></td>
            <td>
                <select name="categoryid" class="form-control" >
                    <option value="0">全部</option>
                    <c:forEach items="${categoryList}" var="category">
                        <option <c:if test="${category.id == entry.categoryid}">selected</c:if> value="${category.id}">${category.name}</option>
                    </c:forEach>
                </select>
            </td>
        </tr>
        <tr class="active">
            <td>
                <label for="uploader">上传人:</label></td>
            <td>
                <input type="text"  value="${entry.uploader}" class="form-control" name="uploader" id="uploader" placeholder="请输入上传人">
            </td>
        </tr>
        <tr class="active">
            <td>
                <label for="uploader">上传时间:</label></td>
            <td>

                <input type="date" value="<fmt:formatDate value='${entry.createdate}' pattern='yyyy-MM-dd'/>"  class="form-control" name="createdate" id="createdate" placeholder="请输入上传时间">
            </td>
        </tr>
        <tr class="danger">
            <td colspan="2">
                <input type="button" onclick="update()" class="btn btn-danger" value="添加评论"/>
            </td>
        </tr>
    </table>
</form>
</body>
<script type="text/javascript" src="${pageContext.request.contextPath }/static/js/jquery.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/static/js/jquery.date.js"></script>
<script>

    $(function () {
        $("#summary").val(${entry.summary})
    })
    function update(){
        var data=$("#form").serialize();

        $.ajax({
            url:"${pageContext.request.contextPath}/entry/update",
            data:data,
            type:"post",
            success:function (result) {
                if (result.code==0){
                    location.href="${pageContext.request.contextPath}/entry/list"
                } else {
                    $("#addInfo").html(result.msg);
                }
            },
            dataType:"json"

        })
    }
</script>
</html>